home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / system / sysprof3.zip / ORIGINAL.ARC / SYS_PROF.ASM < prev   
Assembly Source File  |  1988-06-16  |  30KB  |  780 lines

  1. ;-----------------------------------------------------------------------------;
  2. ;                                                                             ;
  3. ;                                  Listing 1                                  ;
  4. ;                                                                             ;
  5. ;   NAME : SYS_PROF                                                           ;
  6. ;                                                                             ;
  7. ;   DATE : March 24, 1988                                                     ;
  8. ;                                                                             ;
  9. ;   AUTHOR : (C) Copyright 1988 G. Kent Cobb - All Rights Reserved            ;
  10. ;                                                                             ;
  11. ;   DESCRIPTION :                                                             ;
  12. ;       This is the terminate-and-stay-resident portion of a system profiler. ;
  13. ;       It installs several interrupt handlers, which monitor the occurrences ;
  14. ;       and duration of a number of software interrupts.                      ;
  15. ;                                                                             ;
  16. ;-----------------------------------------------------------------------------;
  17.  
  18. ;----------------------------------------------------------------------------;
  19. ;                              Interrupt numbers                             ;
  20. ;----------------------------------------------------------------------------;
  21.  
  22. TIMER_INTERRUPT     EQU 1CH
  23. TERMINATE           EQU 20H
  24. TERM_AND_STAY_RES   EQU 27H
  25. CONTROL_INTERRUPT   EQU 60H
  26.  
  27. ;----------------------------------------------------------------------------;
  28. ;                  MS-DOS functions (Interrupt 21H services)                 ;
  29. ;----------------------------------------------------------------------------;
  30.  
  31. DOS MACRO   OP
  32.     MOV AH,DOS_&OP
  33.     INT 21H
  34.     ENDM
  35.  
  36. DOS_DISPLAY_STRING  EQU 09H
  37. DOS_SET_INT_VECTOR  EQU 25H
  38. DOS_GET_INT_VECTOR  EQU 35H
  39.  
  40. ;----------------------------------------------------------------------------;
  41. ;   This is a list of all the interrupts that are intercepted by SYS_PROF.   ;
  42. ;----------------------------------------------------------------------------;
  43.  
  44. NUMBER_OF_INTERRUPTS        EQU 9
  45.  
  46. PRINT_SCREEN_INTERRUPT      EQU  5H
  47. VIDEO_INTERRUPT             EQU 10H
  48. DISK_INTERRUPT              EQU 13H
  49. COMM_INTERRUPT              EQU 14H
  50. KEYBOARD_INTERRUPT          EQU 16H
  51. PRINTER_INTERRUPT           EQU 17H
  52. DOS_FUNC_INTERRUPT          EQU 21H
  53. ABS_DISK_READ_INTERRUPT     EQU 25H
  54. ABS_DISK_WRITE_INTERRUPT    EQU 26H
  55.  
  56.  
  57. ;----------------------------------------------------------------------------;
  58. ;   These are the number of distinct services defined for each interrupt.    ;
  59. ;   The OCCURRENCES array contains two double words for each service, and    ;
  60. ;   two additional double words for each interrupt.  If an interrupt is      ;
  61. ;   generated with a service number that is out of range, the data for it    ;
  62. ;   will accumulate in this additional bin.                                  ;
  63. ;----------------------------------------------------------------------------;
  64.  
  65. PRINT_SCREEN_SERVICES       EQU 0
  66. VIDEO_SERVICES              EQU 20
  67. DISK_SERVICES               EQU 24
  68. COMM_SERVICES               EQU 4
  69. KEYBOARD_SERVICES           EQU 3
  70. PRINTER_SERVICES            EQU 3
  71. DOS_FUNC_SERVICES           EQU 99
  72. ABS_DISK_READ_SERVICES      EQU 0
  73. ABS_DISK_WRITE_SERVICES     EQU 0
  74.  
  75. ;-----------------------------------------------------------------------;
  76. ;   This macro defines the handling of the intercepted interrupts.  The ;
  77. ;   INT_NUM parameter that the macro expects is an index into the       ;
  78. ;   MAX_SERVICES and OFFSETS tables.                                    ;
  79. ;                                                                       ;
  80. ;   Interrupts 25H and 26H are handled in a manner which is very        ;
  81. ;   similar, but slightly different from the other interrupts.  If this ;
  82. ;   macro is invoked with a second parameter, code is included to       ;
  83. ;   provide the special handling that these interrupts require.         ;
  84. ;-----------------------------------------------------------------------;
  85.  
  86. PERFORM_INTERRUPT MACRO INT_NUM,SPECIAL
  87.  
  88. INTERRUPT_HANDLER&INT_NUM   PROC    FAR
  89.  
  90. ;   Turn interrupts back on.
  91.  
  92.         STI
  93.  
  94. ;   Save the existing interrupt and service numbers on the stack.
  95.  
  96.         PUSH CS:WORD PTR INTERRUPT
  97.  
  98. ;   Push the flags onto the stack now (before we execute any instructions which
  99. ;   might change them) in order to simulate an interrupt later. 
  100.  
  101.         PUSHF
  102.  
  103. ;   Save the value of WATCH on the stack while we're changing INTERRUPT and
  104. ;   SERVICE.
  105.  
  106.         PUSH CS:WATCH
  107.  
  108. ;   Turn accumulation off, set new INTERRUPT and SERVICE values, make sure 
  109. ;   the service number is valid, and then restore accumulation to its previous
  110. ;   state.
  111.  
  112.         MOV  CS:WATCH,0
  113.         MOV  CS:INTERRUPT,&INT_NUM
  114.         MOV  CS:SERVICE,AH
  115.         CALL VALIDATE_SERVICE
  116.         POP  CS:WATCH
  117.  
  118. ;   If accumulation is turned off, go straight to the real ISR.
  119.  
  120.         CMP  CS:WATCH,0
  121.         JE   READY_FOR_INTERRUPT&INT_NUM
  122.  
  123. ;   If accumulation is turned on, push a one onto the stack to tell the
  124. ;   ACCUMULATE routine which bin to increment, and then call it.
  125.  
  126.         PUSH CS:ONE
  127.         CALL ACCUMULATE
  128.  
  129. READY_FOR_INTERRUPT&INT_NUM:
  130.  
  131. ;   After tabulating occurrence data, execute the real ISR
  132.  
  133.         CALL CS:DWORD PTR OLD_INTERRUPT_VECTORS [ 4*(&INT_NUM-1) ]
  134.  
  135. ;   Interrupts 25H and 26H require special handling.  Since they leave the 
  136. ;   flags on the stack when they return control to the calling program, we 
  137. ;   have an extra word on the stack which must be popped.
  138.  
  139. IFNB    <SPECIAL>
  140.         POP  CS:EXTRA_FLAGS
  141. ENDIF
  142.  
  143. ;   On return, pop the interrupt and service numbers that were current before
  144. ;   this one.
  145.  
  146.         POP  CS:WORD PTR INTERRUPT
  147.  
  148. ;   For most interrupts, return with RET 2 rather than IRET.  This will 
  149. ;   preserve whatever treatment the real ISR uses for the flags.
  150.  
  151. IFB     <SPECIAL>
  152.         RET  2
  153.  
  154. ;   Interrupts 25H and 26H are special cases.  The calling program expects the
  155. ;   flags to still be on the stack, so we use RET instead.
  156.  
  157. ELSE
  158.         RET
  159. ENDIF
  160.  
  161. INTERRUPT_HANDLER&INT_NUM   ENDP
  162.  
  163.         ENDM
  164.  
  165.  
  166.  
  167. CODE_SEG    SEGMENT PUBLIC
  168.         ASSUME CS:CODE_SEG , DS:CODE_SEG
  169.     
  170. ;-----------------------------------------------------------------------;
  171. ;   This is the entry point for the program.  Control is immediately    ;
  172. ;   transferred to the initialization code, which is located in the     ;
  173. ;   portion of the program which does not remain resident.              ;
  174. ;-----------------------------------------------------------------------;
  175.  
  176.         ORG 100H                    ; COM FILE
  177.  
  178. JUMP_TO_INIT    PROC    FAR
  179.         JMP  INIT
  180. JUMP_TO_INIT    ENDP
  181.  
  182.  
  183. ;-----------------------------------------------------------------------------;
  184. ;   The handling for all nine intercepted interrupts is very similar, and is  ;
  185. ;   defined by the PERFORM_INTERRUPT macro.  This section contains the macro  ;
  186. ;   calls.                                                                    ;
  187. ;-----------------------------------------------------------------------------;
  188.  
  189. ;   Print screen interrupt
  190.  
  191.         PERFORM_INTERRUPT   1
  192.  
  193. ;   BIOS Video interrupt
  194.  
  195.         PERFORM_INTERRUPT   2
  196.  
  197. ;   BIOS Disk interrupt
  198.  
  199.         PERFORM_INTERRUPT   3
  200.  
  201. ;   BIOS Comm interrupt
  202.  
  203.         PERFORM_INTERRUPT   4
  204.  
  205. ;   BIOS Keyboard interrupt (16H)
  206.  
  207.         PERFORM_INTERRUPT   5
  208.  
  209. ;   BIOS Printer interrupt
  210.  
  211.         PERFORM_INTERRUPT   6
  212.  
  213. ;   DOS Function calls interrupt
  214.  
  215.         PERFORM_INTERRUPT   7
  216.  
  217. ;   The last two interrupts, 25H and 26H, require special handling since the
  218. ;   real ISRs do not pop the flags from the stack upon completion.  By passing
  219. ;   a second parameter to the PERFORM_INTERRUPT macro, the code to handle this 
  220. ;   will be included by the preprocessor when the macro is expanded.
  221.  
  222. ;   DOS Ab